<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:p="http://primefaces.org/ui"
      >

    <h:body>

        <ui:composition template="/resources/template/template.xhtml">


            <ui:define name="content">
                <h:form  >
                    <h:panelGroup  rendered="#{!webUserController.hasPrivilege('AdminManagingUsers')}"  >
                        <p:outputLabel value="YOU ARE NOT AUTHERIZED." ></p:outputLabel>
                    </h:panelGroup>
                    <p:panelGrid columns="2"  rendered="#{webUserController.hasPrivilege('AdminManagingUsers')}" >                   

                        <p:panel header="Manage User Privilages"   >


                            <f:facet name="header" >
                                <h:outputLabel value="Manage User Privilages"/>
                                <p:commandButton value="Update User Privilage"  action="#{userPrivilageController.savePrivileges()}" ajax="false" onclick="onSubmitButton();" >  
                                </p:commandButton>


                                <p:commandButton ajax="false" value="Back" action="#{webUserController.backToViewUsers()}" >
                                </p:commandButton>

                            </f:facet>

                            <h:panelGrid  columns="2" >                          

                                <p:autoComplete id="user" converter="webUs" forceSelection="true"  completeMethod="#{webUserController.completeUser}" var="us" 
                                                itemLabel="#{us.webUserPerson.name}" itemValue="#{us}"  
                                                value="#{userPrivilageController.currentWebUser}" >
                                    <f:ajax event="itemSelect" execute="user" render="tree" />
                                </p:autoComplete>
                            </h:panelGrid>


                            <p:panel id="tree">
                                <p:growl id="messages" showDetail="true" escape="false"/>  
                                <p:tree value="#{userPrivilageController.tmp}" var="node"  
                                        selectionMode="checkbox" 
                                        selection="#{userPrivilageController.selectedNodes}">  
                                    <p:treeNode>  
                                        <h:outputText value="#{node}" />  
                                    </p:treeNode>  
                                </p:tree>  


                            </p:panel>
                        </p:panel>
                    </p:panelGrid>

                </h:form>



            </ui:define>

        </ui:composition>

    </h:body>

</html>
